package com.chinasoft.bigdatadisplay.controller;


import com.chinasoft.bigdatadisplay.entity.*;
import com.chinasoft.bigdatadisplay.result.Result;
import com.chinasoft.bigdatadisplay.service.ResultDisplayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@CrossOrigin
@RestController
public class ResultDisplayController {

    @Autowired
    private ResultDisplayService resultDisplayService;







    //根据location查询平均消费能力
    @GetMapping("/queryAvgConsumptionOfLocation")
    public Result<AvgConsumptionOfLocation> getAvgConsumptionOfLocation(
            @RequestParam(required = true) String location) {
        try {
            return Result.success(resultDisplayService.getAvgConsumptionOfLocation(location));
        } catch (Exception e){
            return Result.error("获取数据失败：" + e.getMessage());
        }
    }

    //根据age查询平均消费能力
    @GetMapping("/queryAvgConsumptionOfAge")
    public Result<AvgConsumptionOfAge> getAvgConsumptionOfAge(
            @RequestParam(required = true) String age){
        try {
            return Result.success(resultDisplayService.getAvgConsumptionOfAge(age));
        } catch (Exception e){
            return Result.error("获取数据失败：" + e.getMessage());
        }
    }

    //根据age查询商品category的总数量
    @GetMapping("/querySumCategory")
    public Result< List<SumCategoryOfAge> > getCategorySumOfAge(
            @RequestParam(required = true) String age) {
        try {
            return Result.success(resultDisplayService.getSumCategoryOfAge(age));
        } catch (Exception e){
            return Result.error("获取数据失败：" + e.getMessage());
        }
    }

    //brand_sales_stats获取品牌的总销量和总销售额
    @GetMapping("/queryBrandOfSales")  // 路径与请求保持一致
    public Result<List<BrandSalesStats>> getBrandSalesStats() {
        try {
            // 调用Service层方法（需确保Service和Mapper已正确实现）
            List<BrandSalesStats> result = resultDisplayService.getBrandSalesStats();
            return Result.success(result);
        } catch (Exception e) {
            return Result.error("获取品牌销售数据失败：" + e.getMessage());
        }
    }

    // 获取种类的销售信息
    @GetMapping("/queryCategoryOfSales")  // 路径与请求保持一致
    public Result<List<CategorySalesStats>> getCategorySalesStats() {
        try {
            // 调用Service层方法（需确保Service和Mapper已正确实现）
            List<CategorySalesStats> result = resultDisplayService.getCategorySalesStats();
            return Result.success(result);
        } catch (Exception e) {
            return Result.error("获取品牌销售数据失败：" + e.getMessage());
        }
    }

    //获取获取男女的销售额和占比
    @GetMapping("/queryGenderOfSales")
    public Result<List<GenderSalesSummary>> getGenderSalesStats() {
        try {
            // 调用Service层方法（需确保Service和Mapper已正确实现）
            List<GenderSalesSummary> result = resultDisplayService.getGenderSalesSummary();
            return Result.success(result);
        } catch (Exception e) {
            return Result.error("获取品牌销售数据失败：" + e.getMessage());
        }
    }

    @GetMapping("/sales/monthly")
    public Result<List<MonthlySalesStats>> listAllSalesStats() {
        return resultDisplayService.listAllSalesStats();
    }

    @GetMapping("/queryUserPurchaseStats")
    public  Result<List<UserPurchaseStats>> getUserPurchaseStats() {
        try {
            // 调用Service层方法（需确保Service和Mapper已正确实现）
            List<UserPurchaseStats> result = resultDisplayService.getUserPurchaseStats();
            return Result.success(result);
        } catch (Exception e) {
            return Result.error("获取用户购买数据失败：" + e.getMessage());
        }
    }
}